package com.member.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.member.shop.vo.GoodsRefundListVo;
import org.springframework.security.access.prepost.PreAuthorize;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import javax.annotation.Resource;

import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.enums.BusinessType;
import com.member.shop.domain.SysBizOrderService;
import com.member.shop.service.ISysBizOrderServiceService;
import com.member.common.utils.poi.ExcelUtil;
import com.member.common.core.page.TableDataInfo;
/**
 * 【订单售后】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-03-21
 **/
@RestController
@RequestMapping("/shop/service")
public class SysBizOrderServiceController extends BaseController {
    @Resource
    private ISysBizOrderServiceService sysBizOrderServiceService;

    /**
     * 查询订单售后列表
     */
    @PreAuthorize("@ss.hasPermi('shop:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizOrderService sysBizOrderService) {
        startPage();
//        LambdaQueryWrapper<SysBizOrderService> queryWrapper = new LambdaQueryWrapper<SysBizOrderService>();
        List<SysBizOrderService> list = sysBizOrderServiceService.selectSysBizOrderServiceList(sysBizOrderService);
        if (!CollectionUtils.isEmpty(list)) {
            for (SysBizOrderService bizOrderService : list) {
                String goodsInfo = bizOrderService.getGoodsInfo();
                List<GoodsRefundListVo> goodsRefundListVoS = JSON.parseArray(goodsInfo, GoodsRefundListVo.class);
                bizOrderService.setGoodsRefundList(goodsRefundListVoS);
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出订单售后列表
     */
    @PreAuthorize("@ss.hasPermi('shop:service:export')")
    @Log(title = "订单售后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizOrderService sysBizOrderService) {
        LambdaQueryWrapper<SysBizOrderService> queryWrapper = new LambdaQueryWrapper<SysBizOrderService>();
        List<SysBizOrderService> list = sysBizOrderServiceService.selectSysBizOrderServiceList(queryWrapper);
        ExcelUtil<SysBizOrderService> util = new ExcelUtil<SysBizOrderService>(SysBizOrderService. class);
        util.exportExcel(response, list, "订单售后数据");
    }

    /**
     * 获取订单售后详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:service:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        SysBizOrderService sysBizOrderService = sysBizOrderServiceService.selectSysBizOrderServiceById(id);

        if (sysBizOrderService!=null) {
            String goodsInfo = sysBizOrderService.getGoodsInfo();
            List<GoodsRefundListVo> goodsRefundListVoS = JSON.parseArray(goodsInfo, GoodsRefundListVo.class);
            sysBizOrderService.setGoodsRefundList(goodsRefundListVoS);
        }

        return success(sysBizOrderService);
    }

    /**
     * 新增订单售后
     */
    @PreAuthorize("@ss.hasPermi('shop:service:add')")
    @Log(title = "订单售后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizOrderService sysBizOrderService) {
        return toAjax(sysBizOrderServiceService.insertSysBizOrderService(sysBizOrderService));
    }

    /**
     * 修改订单售后
     */
    @PreAuthorize("@ss.hasPermi('shop:service:edit')")
    @Log(title = "订单售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizOrderService sysBizOrderService) {
        return toAjax(sysBizOrderServiceService.updateSysBizOrderService(sysBizOrderService));
    }




    /**
     * 修改订单售后
     */
    @PreAuthorize("@ss.hasPermi('shop:service:edit')")
    @Log(title = "订单售后", businessType = BusinessType.UPDATE)
    @PutMapping("/statusUpdate")
    public AjaxResult statusUpdate(@RequestBody SysBizOrderService sysBizOrderService) {
        sysBizOrderService.setAuditBy(getUsername());
        return toAjax(sysBizOrderServiceService.statusUpdate(sysBizOrderService));
    }

    /**
     * 删除订单售后
     */
    @PreAuthorize("@ss.hasPermi('shop:service:remove')")
    @Log(title = "订单售后", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizOrderServiceService.deleteSysBizOrderServiceByIds(ids));
    }
}
